package example.cloudsitemanagement8001.service.impl;

import example.cloudsitemanagement8001.dto.SiteInfoQueryDTO;
import example.cloudsitemanagement8001.entity.SiteInfo;
import example.cloudsitemanagement8001.mapper.SiteInfoMapper;
import example.cloudsitemanagement8001.service.SiteInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class SiteInfoServiceImpl implements SiteInfoService {
    @Autowired
    private SiteInfoMapper siteInfoMapper;
    @Override
    public PageInfo<SiteInfo> listSites(SiteInfoQueryDTO queryDTO) {
        PageHelper.startPage(queryDTO.getPageNum(), queryDTO.getPageSize());
        List<SiteInfo> sites = siteInfoMapper.selectSiteInfoList(queryDTO.getName());
        return new PageInfo<>(sites);
    }
    @Override
    public PageInfo<SiteInfo> listSiteOptions(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<SiteInfo> sites = siteInfoMapper.selectSiteInfoList(null);
        return new PageInfo<>(sites);
    }
    @Override
    public SiteInfo getSiteById(Long id) {
        return siteInfoMapper.selectSiteInfoById(id);
    }
    @Override
    public boolean addSite(SiteInfo siteInfo) {
        siteInfo.setCreateTime(LocalDateTime.now());
        siteInfo.setUpdateTime(LocalDateTime.now());
        return siteInfoMapper.insertSiteInfo(siteInfo) > 0;
    }
    @Override
    public boolean updateSite(SiteInfo siteInfo) {
        siteInfo.setUpdateTime(LocalDateTime.now());
        return siteInfoMapper.updateSiteInfoById(siteInfo) > 0;
    }
    @Override
    public boolean deleteSite(Long id) {
        return siteInfoMapper.deleteSiteInfoById(id) > 0;
    }
}
